//
//  InitViewController.swift
//  BookStore2.0
//
//  Created by hw on 2022/5/31.
//

import UIKit

class InitViewController: UIViewController {

    
    @IBOutlet weak var UserName: UITextField!
    
    @IBOutlet weak var pwd: UITextField!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        UserName.text=UserDefaults.standard.object(forKey: "userName") as? String
        DB1.downloadBookInfo()
        // Do any additional setup after loading the view.
    }
    
    @IBAction func UserLogin(_ sender: Any) {
        
        let defaultpwd=UserDefaults.standard.object(forKey:"passwd") as? String
        
        if pwd.text==defaultpwd
        {
            let mainBoard:UIStoryboard!=UIStoryboard(name:"Main",bundle:nil)
            let Initialsb=mainBoard.instantiateViewController(withIdentifier:"Initial")
            UIApplication.shared.windows[0].rootViewController=Initialsb
           
        }
        else
        {
            let p=UIAlertController(title:"登录失败",message:"用户名或密码错误",preferredStyle:.alert)
            p.addAction(UIAlertAction(title:"确定",style:.default,handler:{
                (
                    act:UIAlertAction)in self.pwd.text=""
            }))
            present(p,animated:false,completion:nil)
        }
    }
}
